//
//  ZYCScheduleRootCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/20.
//

#import "ZYCScheduleRootCell.h"
#import "ZYCLectureRecordsModel.h"
#import "ZYCScheduleModel.h"
#import "BTTitleImageButton.h"
@interface ZYCScheduleRootCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *addressLabel;
@property (nonatomic, strong) BTTitleImageButton *statusButton;
@property (nonatomic, strong) UILabel *statusLabel;

@end
@implementation ZYCScheduleRootCell

- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    _titleLabel.text = dict[@"title"];
    _addressLabel.text = dict[@"names"];
}
//类型(1-教师日程，2-教师值班记录，3-家长日程)
- (void)setSModel:(ZYCScheduleModel *)sModel{
    _sModel = sModel;
    NSInteger type = [sModel.type integerValue];
    _titleLabel.text = sModel.title;
    if (type  == 1) {//教师日程
        _addressLabel.text = [NSString stringWithFormat:@"授课地点:%@",sModel.courseAddress];
    }else if(type == 2){//值班记录
        _addressLabel.text = [NSString stringWithFormat:@"值班人员:%@",sModel.dutyPersonnel];
    }else{//家长日程
        _addressLabel.text = [NSString stringWithFormat:@"值班人员:%@",sModel.dutyPersonnel];
    }


}

//巡堂状态（1：正常；2：迟到；3：取消；4：异常）
- (void)setModel:(ZYCLectureRecordsModel *)model{
    _model = model;
    _titleLabel.text = model.className;
    _addressLabel.text = [NSString stringWithFormat:@"授课地点:%@",model.courseAddress];
    if ([model.isObjection integerValue] == 1) {//已处理
        _statusButton.hidden = YES;
        _statusLabel.hidden = NO;
        _statusLabel.text = @"已处理";
    }else{//未处理
        if ([model.classStatus isEqualToString:@"4"]) {
            _statusButton.hidden = NO;
            _statusLabel.hidden = YES;
            [_statusButton setTitle:@"处理异常" forState:UIControlStateNormal];                   [_statusButton setImage:[UIImage imageNamed:@"Path-1"] forState:UIControlStateNormal];
        }else{
            _statusButton.hidden = YES;
            _statusLabel.hidden = YES;
        }
    }
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = HEX_RGB(@"#FAFAFA");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.addressLabel];
        [self.contentView addSubview:self.statusButton];
        [self.contentView addSubview:self.statusLabel];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(15.0f);
            make.left.equalTo(self.contentView).offset(21.0f);
        }];
        
        [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView).offset(-15.0f);
            make.right.equalTo(self.contentView).offset(-21.0f);
            make.left.equalTo(self.contentView).offset(21.0f);
        }];
        
        [self.statusButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-21.0f);
            make.centerY.equalTo(self.titleLabel);
        }];
        
        [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-21.0f);
            make.centerY.equalTo(self.titleLabel);
        }];

        

    }
    return self;
}


- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 18) titleColor:HEX_RGB(@"#333333") textAlignment:ZZTextAlignmentLeft];
    }
    return _titleLabel;
}


- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15) titleColor:HEX_RGB(@"#8E8E8E") textAlignment:ZZTextAlignmentLeft];
        _addressLabel.numberOfLines = 0;
    }
    return _addressLabel;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 13.0f) titleColor:HEX_RGB(@"#2079D3") textAlignment:ZZTextAlignmentLeft];
    }
    return _statusLabel;
}


- (BTTitleImageButton *)statusButton {
    if (!_statusButton) {
        _statusButton = [[BTTitleImageButton alloc] init];
        [_statusButton setTitleColor:HEX_RGB(@"#2079D3") forState:UIControlStateNormal];
        _statusButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 13.0f);
        [_statusButton addTarget:self action:@selector(clickExceptAction:) forControlEvents:UIControlEventTouchUpInside];
        _statusButton.hidden = YES;
    }
    return _statusButton;
}

- (void)clickExceptAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(scheduleRootCellDidDealExceptWithModel:)]) {
        [self.delegate scheduleRootCellDidDealExceptWithModel:self.model];
    }
}
@end
